

require(['jquery','bootstrapValidator'], function ($) {
    $(function () {
        // 获取form表单
        var $form = $('form');
        // 一、初始化表单验证
        $form.bootstrapValidator({
            // 状态图标
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            // 检验字段
            fields: {
                username: {
                    validators: {
                        notEmpty: {
                            message: '用户名不能为空'
                        },
                        stringLength: {
                            min: 4,
                            max: 10,
                            message: '用户名在4-10位'
                        },
                        callback: {
                            message: '用户名错误'
                        }
                    }
                },
                password: {
                    validators: {
                        notEmpty: {
                            message: '密码不能为空'
                        },
                        stringLength: {
                            min: 6,
                            max: 10,
                            message: '密码在6-10位'
                        },
                        callback: {
                            message: '密码错误'
                        }
                    }
                }
            }
        })
        // 
        var bootstrapValidator = $form.data('bootstrapValidator');
        // 二、验证通过
        $form.on('success.form.bv', function (e) {
            e.preventDefault();
            $.ajax({
                url: '/employee/employeeLogin',
                type: 'post',
                data: $form.serialize(),
                success: function (info) {
                    console.log(info)
                    if (info.success) {
                        location.href = 'index.html'
                    }
                    if (info.error === 1000) {
                        bootstrapValidator.updateStatus('username', 'INVALID', 'callback')
                    }
                    if (info.error === 1001) {
                        bootstrapValidator.updateStatus('password', 'INVALID', 'callback')
                    }
                }
            })
        })
        // 三、重置表单
        $('[type="reset"]').on('click', function () {
            bootstrapValidator.resetForm()
        })
    
    
    })
})